
import { Agent } from 'grey-agent';
import { message } from 'antd';
import Controller from 'Controller';

interface IAgentOpt {
    /** 是否显示错误信息 默认显示 */
    errorMessage?: boolean
}

const agent = new Agent<IAgentOpt>()

agent.domain = '';
agent.context = '';

agent.use('before', async e => {
    e.request.set({ 'ldteProjectPath': Controller.instance.state.project.path });
    return e;
})

agent.use('after', async e => {
    if (e.option.errorMessage === false) return e;
    if (e.response?.error) {
        if (e.response.error.message) {
            message.error(e.response.error.message);
        }
    }
    return e;
})

export default agent;